package com.qf.data.service.impl;

import com.qf.common.bean.R;
import com.qf.data.service.CheckCodeService;
import com.qf.data.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author 千锋健哥
 */
@Service
public class CheckCodeServiceImpl implements CheckCodeService {

    @Autowired
    private RedisUtil redisUtil;

    @Override
    public R saveToRedis(String phone, String code) {
        redisUtil.setKey(phone, code, 10, TimeUnit.MINUTES);
        return R.ok();
    }

    @Override
    public R<String> getCode(String phone) {
        String code = redisUtil.getKey(phone, String.class);
        return R.ok(code);
    }

}
